import org.molamil.acto.core.EventConstants;
import org.molamil.acto.core.Logger;
import org.molamil.acto.pages.master.AbstractLinkedMaster;
import org.molamil.acto.pages.master.AbstractMovieMaster;
import org.molamil.acto.pages.master.CallerManager;
import org.molamil.acto.pages.master.MovieMaster;
import org.molamil.acto.pages.master.MovieMasterDelegate;

/**
 * <code>MovieMaster</code> that uses linked <code>MovieClip</code>'s from the library as pages.
 *
 * @author Jorge Hernandez
 */
class org.molamil.acto.pages.master.LinkedMovieMaster extends AbstractLinkedMaster implements MovieMaster {

	
	// Properties
	
	private static var log:Logger = Logger.getLogger("LinkedMovieMaster");
	
	private var movieMasterDelegate:MovieMasterDelegate;
	private var callerManager:CallerManager;
	
	
	// Constructor
	
	public function LinkedMovieMaster() {
		log.debug("Constructor");
		movieMasterDelegate = new MovieMasterDelegate(this);
		callerManager = new CallerManager();
	}
	
	
	// Functions
	
	public function display():Void {
		
		log.info("display(), name = " + context.name);
		
		super.display();
		
		var eventObject:Object = {target: this, type: EventConstants.MOVIE_DISPLAY};
		dispatchEvent(eventObject);
		
	}
	
	public function clear():Void {
		
		log.info("clear(), name = " + context.name);
		
		super.clear();
		
		var eventObject:Object = {target: this, type: EventConstants.MOVIE_CLEAR};
		dispatchEvent(eventObject);
		
	}
	
	private function mcStateChangeListener(eventObject:Object):Void {
		
		super.mcStateChangeListener(eventObject);
		
		log.debug("mcStateChangeListener(), state = " + eventObject.state);
		
		movieMasterDelegate.mcStateChangeListener(eventObject);
		
	}
	
	public function addCaller(name:String):Void {
		callerManager.addCaller(name);
	}
	
	public function removeCaller(name:String):Void {
		callerManager.removeCaller(name);
	}
	
	public function existsCaller(name:String):Boolean {
		return callerManager.existsCaller(name);
	}
	
	public function getCallers():Array {
		return callerManager.getCallers();
	}
	
	
}